# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=scandir
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.10.0
pkgrel=1
pkgdesc="A better directory iterator and faster os.walk() (mingw-w64)"
url="https://github.com/benhoyt/scandir"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/benhoyt/scandir/archive/v${pkgver}.tar.gz)
sha256sums=('73a773c58432ce28f32286f2892217101f4cf61ff4bccd8829ebaa7af7c56620')

prepare() {
  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r ${_realname}-${pkgver} build-python-${CARCH}
}

build() {
  cd ${srcdir}/build-python-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  CPPFLAGS+=" -D_WIN32_WINNT=0x0600" \
    ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd ${srcdir}/build-python-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --root=${pkgdir} --prefix=${MINGW_PREFIX} --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
